import Vue from 'vue'
import store from '@/store'
import DataDict from './dict'
import api from "@/api/api.js"

function searchDictByKey(dict, key) {
  if (key == null && key == "") {
    return []
  }
  try {
    for (let i = 0; i < dict.length; i++) {
      if (dict[i].type == key) {
        return dict[i].dataList
      }
    }
  } catch (e) {
    return []
  }
}

function install() {
  Vue.use(DataDict, {
    metas: {
      '*': {
        labelField: 'dictLabel',
        valueField: 'dictValue',
        request(dictMeta) {
			console.info("store.state.dict.dictList",store.state.dict.dictList)
          const storeDict = searchDictByKey(store.state.dict.dictList, dictMeta.type)
          if (storeDict) {
            return new Promise(resolve => { resolve(storeDict) })
          }else{
			return new Promise(resolve => { resolve([]) })
		  }
        },
      },
    },
  })
}

export default {
  install,
}